package com.mapbased.da;

import java.io.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: mapbased.com</p>
 *
 * @author chy_hs(Baily)
 * @version 1.0
 */
public class SizeInputStream
    extends InputStream
{
    InputStream real;
    long size;
    public SizeInputStream(InputStream real,long size)
    {
        super();
        this.real=real;
        this.size=size;
    }
    public SizeInputStream(java.io.File f)
        throws FileNotFoundException
    {
        this.real=new java.io.FileInputStream(f);
        this.size=f.length();

    }

    public long getSize()
    {
        return size;
    }

    /**
     * Reads the next byte of data from the input stream.
     *
     * @return the next byte of data, or <code>-1</code> if the end of the
     *   stream is reached.
     * @throws IOException if an I/O error occurs.
     * @todo Implement this java.io.InputStream method
     */
    public int read()
        throws IOException
    {
        return real.read();
    }


    /**
     * Returns the number of bytes that can be read (or skipped over) from
     * this input stream without blocking by the next caller of a method for
     * this input stream.
     *
     * @return the number of bytes that can be read from this input stream
     *   without blocking.
     * @throws IOException if an I/O error occurs.
     * @todo Implement this java.io.InputStream method
     */
    public int available()
        throws IOException
    {
        return real.available();
    }

    /**
     * Closes this input stream and releases any system resources associated
     * with the stream.
     *
     * @throws IOException if an I/O error occurs.
     * @todo Implement this java.io.InputStream method
     */
    public void close()
        throws IOException
    {
        real.close();
    }

    /**
     * Marks the current position in this input stream.
     *
     * @param readlimit the maximum limit of bytes that can be read before
     *   the mark position becomes invalid.
     * @todo Implement this java.io.InputStream method
     */
    public synchronized void mark(int readlimit)
    {
        real.mark(readlimit);
    }

    /**
     * Tests if this input stream supports the <code>mark</code> and
     * <code>reset</code> methods.
     *
     * @return <code>true</code> if this stream instance supports the mark
     *   and reset methods; <code>false</code> otherwise.
     * @todo Implement this java.io.InputStream method
     */
    public boolean markSupported()
    {
        return real.markSupported();
    }

    /**
     * Reads some number of bytes from the input stream and stores them into
     * the buffer array <code>b</code>.
     *
     * @param b the buffer into which the data is read.
     * @return the total number of bytes read into the buffer, or
     *   <code>-1</code> is there is no more data because the end of the
     *   stream has been reached.
     * @throws IOException if an I/O error occurs.
     * @todo Implement this java.io.InputStream method
     */
    public int read(byte[] b)
        throws IOException
    {
        return real.read(b);
    }

    /**
     * Reads up to <code>len</code> bytes of data from the input stream into
     * an array of bytes.
     *
     * @param b the buffer into which the data is read.
     * @param off the start offset in array <code>b</code> at which the data
     *   is written.
     * @param len the maximum number of bytes to read.
     * @return the total number of bytes read into the buffer, or
     *   <code>-1</code> if there is no more data because the end of the
     *   stream has been reached.
     * @throws IOException if an I/O error occurs.
     * @todo Implement this java.io.InputStream method
     */
    public int read(byte[] b,int off,int len)
        throws IOException
    {
        return real.read(b,off,len);
    }

    /**
     * Repositions this stream to the position at the time the
     * <code>mark</code> method was last called on this input stream.
     *
     * @throws IOException if this stream has not been marked or if the mark
     *   has been invalidated.
     * @todo Implement this java.io.InputStream method
     */
    public synchronized void reset()
        throws IOException
    {
        real.reset();
    }

    /**
     * Skips over and discards <code>n</code> bytes of data from this input
     * stream.
     *
     * @param n the number of bytes to be skipped.
     * @return the actual number of bytes skipped.
     * @throws IOException if an I/O error occurs.
     * @todo Implement this java.io.InputStream method
     */
    public long skip(long n)
        throws IOException
    {
        return real.skip(n);
    }
}
